<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>人事管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/xadmin.css">
     <script src="../../static/js/jquery-1.12.4.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/xadmin.js"></script>
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form">
			
			<input type="hidden" name='id' id='id'>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>标题
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="title" name="title" lay-verify="required" 
                        autocomplete="off" class="layui-input">
                </div>
              
            </div>

			 <div class="layui-form-item">
            	<label class="layui-form-label">
                    <span class="x-red">*</span>描述
                </label>
	        </div>
	        <div class="layui-form-item">
	 		<textarea id="demo" style="display: none;" name="content"></textarea>
	 		</div>
			<div class="layui-upload layui-form-item">
			  <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
			  <button type="button" class="layui-btn" id="test9">开始上传</button>
			</div>
			<div class="layui-form-item">
			<input name='filename' id='filename'>
			</div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                </label>
                <button class="layui-btn" lay-filter="add" lay-submit="">
                    &nbsp;&nbsp;提交&nbsp;&nbsp;
                </button>
            </div>
        </form>
    </div>
    <script>
      layui.use(['form','layer','layedit','upload'], function(){
          $ = layui.jquery;
        var form = layui.form
        ,layer = layui.layer
        ,upload = layui.upload;
        var layedit = layui.layedit;
        var myLayedit = layedit.build('demo', {
      	  tool: ['strong' //加粗
      		  ,'italic' //斜体
      		  ,'underline' //下划线
      		  ,'del' //删除线
      		  ,'|',,'left', 'center', 'right', '|', 'face']
      }); //建立编辑器
      
    //选完文件后不自动上传
      upload.render({
        elem: '#test8'
        ,url: '../../upload.action' //改成您自己的上传接口
        ,auto: false
        ,exts: 'txt|docx|doc' 
        ,accept: 'file' //普通文件
        //,multiple: true
        ,bindAction: '#test9'
        ,before: function(obj){
        		layer.msg('文件上传中...', {
        		icon: 16,
        		shade: 0.01,
        		time: 0
        		})
        	}
        ,done: function(res){
          layer.msg('上传成功');
          $('#filename').val(res.url);
          console.log(res.url)
        }
      });

      var data = JSON.parse(localStorage.getItem("data"));// JSno字符串转为对象
      $("#id").val(data.id);
      $("#title").val(data.title);
      $("#filename").val(data.fileName);
      layedit.setContent(myLayedit,data.remark);
      
      form.render();//重载表单
        //自定义验证规则
        form.verify({
          nikename: function(value){
            if(value.length < 2){
              return '昵称至少得2个字符啊';
            }
          }
        });

        //监听提交
        form.on('submit(add)', function(data){
        	var remark = layedit.getContent(myLayedit);
        	var title = $('#title').val();
        	var filename = $('#filename').val();
        	var id = $('#id').val()
            $.ajax({
                url: '../../updDocument.action',
                type: 'post',
                data: {remark,title,filename,id},
                success: function (data) {
                    if (data == 1) {
                        layer.alert("修改成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //修改成功后刷新父界面
                            window.parent.location.reload();
                        });
                    }
                    else {
                        layer.alert("修改失败！")
                    }
                },
                error: function (e) {
                    layer.alert("error！提交失败！")
                },

            });
          return false;
        });
        
        
      });
  </script>
   
  </body>

</html>